<template>


  <SearchTablePage :search-config="baseTableSearchModel" :table-config="baseTableModel" />

</template>

<script lang="ts" setup>
defineOptions({
  name: 'DrillExamSubjectPageData',   //全局别名
  title: '表格页',   //标题
});
import DrillInfoApi from '~/src/api/webPath/DrillInfoApi';
// 接口
import DrillExamSubjectApi from '/@/api/webPath/DrillExamSubjectApi.ts';


import FORM_FIELD_TYPE from '/@/constants/FormFieldType';
import VDialog from '/@/utils/dialogUtil.ts'

const router = useRouter();
const baseTable = ref(null as any);
const baseTableSearch = ref(null as any);
const editRef = ref<any>(null);
const drillList = ref([])

onBeforeMount(async () => {
  const res = await DrillInfoApi.getFilteredPageData({ _size: 999, _current: 1 })
  if (res) {
    const { data: { records: data } } = res
    console.log("drill list data11111", data)
    drillList.value = data.map(x => ({ value: x.id, label: x.drillName }))
  }
})

// 表格搜索初始化searchModel
const baseTableSearchModel = ref({
  columnCount: 4,
  expandLimit: 6,
  autoFit: true,
  columnWidth: '300px',
  labelPosition: 'right',
  labelWidth: '100px',
  items: [ //搜索项初始化

    // { //             label: "id",
    //             field: "id",
    //             clearable: true,
    //             type: FORM_FIELD_TYPE.INPUT,

    //            placeholder:"请输入",

    //         },

    // {
    //   label: "题目类型",
    //   field: "subjectType",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    {
      label: "活动名称",
      field: "drillId",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    // {
    //   label: "是否必考",
    //   field: "mandatory",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
    //   // options: subjectTypeList,
    //   options: [
    //     {
    //       value: '否',
    //       label: "否"
    //     },
    //     {
    //       value: '是',
    //       label: "是"
    //     },
    //   ],

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },
    // {
    //   label: "试题难度",
    //   field: "subjectDifficulty",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    {
      label: "题目内容",
      field: "subjectContent",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

    },

    // {
    //   label: "选项A",
    //   field: "optionA",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,
    //   placeholder: "请输入",
    // },

    // {
    //   label: "选项B",
    //   field: "optionB",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "选项C",
    //   field: "optionC",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "选项D",
    //   field: "optionD",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "选项E",
    //   field: "optionE",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "选项F",
    //   field: "optionF",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "正确答案",
    //   field: "answer",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "备选1",
    //   field: "spareOne",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "备选2",
    //   field: "spareTwo",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "备选3",
    //   field: "spareThree",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "备选4",
    //   field: "spareFour",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "创建人",
    //   field: "creator",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "修改人",
    //   field: "reviser",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "排序",
    //   field: "sort",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    // },

    // {
    //   label: "创建时间",
    //   field: "create_time",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.DATE_RANGE,
    //   placeholder: "请输入",

    //   config: {
    //     props: {   //日期精度配置
    //       type: "daterange",
    //       startPlaceholder: "开始日期",
    //       endPlaceholder: "结束日期",
    //       format: "YYYY-MM-DD",
    //     }
    //   },
    // },

  ],

  buttons: [    //功能区域


    {
      name: "新增",
      buttonClass: 'primary',
      width: 100,
      click: ({ row, handlers }) => {        // 点击回调事件方法钩子，  点击触发

        VDialog.open({
          title: '新增',

          content: { //内容初始形式
            type: 'component', //text:"",预留文本
            name: '/drillExamSubject/edit',
            query: {},

          },

          callBack: (data: any) => {
            handlers.refresh()
          },
          onClose: () => {
            console.log("对话框已关闭");
          },
        });

      },
    },
    {
      name: "导入",
      buttonClass: 'primary',
      width: 100,
      click: ({ row, handlers }) => {   //暴露的方法钩子
        //  CompanyInfoApi.pageDataXls( handlers.getRequestParams(),handlers.getXlsTitle())
        VDialog.open({
          title: '导入',
          content: { //内容初始形式
            type: 'component', //text:"",预留文本
            name: '/AttachmentUpload',
            // query: { companyInfoId: row.id },
          },
          config: {
            additionalParamLabel: "关联活动",
            additionalParamKey: "drillId",
            paramMessage: "请选择关联活动",
            additionalParamOptions: drillList,
            doUpload: DrillExamSubjectApi.uploadExcel,
            doBatchSave: DrillExamSubjectApi.batchSave,
            templateType: "company_template_type_14"

          },
          callBack: (data: any) => {
            handlers.refresh()
            console.log("refresh", handlers.refresh)
            // handlers.refresh()
            console.log("upload recived data:", data)
          },
          onClose: () => {
            console.log("对话框已关闭");
          },
        })
      }
    },
    {
      name: "导出",
      buttonClass: 'primary',
      width: 100,
      click: ({ row, handlers }) => {   //暴露的方法钩子
        VDialog.open({
          title: '导出',
          content: { //内容初始形式
            type: 'component', //text:"",预留文本
            name: '/drillExamSubject/select',
            // query: { companyInfoId: row.id },
          },
          config: {
            drillList,
          },
          callBack: (data: any) => {
            if (data !== '') {
              DrillExamSubjectApi.pageDataXls(handlers.getRequestParams(), handlers.getXlsTitle(), data)
            }
            handlers.refresh()
            console.log("refresh", handlers.refresh)
            // handlers.refresh()
            console.log("upload recived data:", data)
          },
          onClose: () => {
            console.log("对话框已关闭");
          },
        })
      }
    },
    {
      name: "批量删除",
      buttonClass: 'danger',
      width: 100,
      isShow: (row: any) => {
        return false;
      },
      click: () => {   //暴露的方法钩子
        console.log(baseTable.value.getSelection());
      },
    },
  ]
})
// 表格初始化Model
const baseTableModel = ref({
  border: true,
  pagination: true,
  inline: true,
  selectable: true,
  isFullscreen: false,
  tooltip: true,
  minWidth: '200px',
  data: {    //table  初始化
    current: 1,
    size: 10,
    total: 100,
    data: []
  },
  requestData: { api: DrillExamSubjectApi.getPageData, query: {} },   //数据源 参数有效性： 'steady|transient'
  columns: [
    {
      label: "活动名称",
      field: "drillName",
      width: 100,
    },
    {
      label: "题目类型",
      field: "subjectType",
      width: 180,
    },
    {
      label: "是否必考",
      field: "mandatory",
      width: 180,
      // fieldFormat: 'tag',
      // // valueMap: checkResultEnumList,
      // valueMap: [
      //   {
      //     value: '是',
      //     label: "是",
      //     type: "primary"
      //   },
      //   {
      //     value: '否',
      //     label: "否",
      //     type: "success"
      //   },
      // ],

    },
    {
      label: "题目内容",
      field: "subjectContent",
      width: 180,
    },
    {
      label: "选项A",
      field: "optionA",
      width: 180,
    },
    {
      label: "选项B",
      field: "optionB",
      width: 180,
    },
    {
      label: "选项C",
      field: "optionC",
      width: 180,
    },
    {
      label: "选项D",
      field: "optionD",
      width: 180,
    },
    {
      label: "选项E",
      field: "optionE",
      width: 180,
    },
    {
      label: "选项F",
      field: "optionF",
      width: 180,
    },
    {
      label: "正确答案",
      field: "answer",
      width: 180,
    },
    // {
    //   label: "备选1",
    //   field: "spareOne",
    //   width: 180,
    // },
    // {
    //   label: "备选2",
    //   field: "spareTwo",
    //   width: 180,
    // },
    // {
    //   label: "备选3",
    //   field: "spareThree",
    //   width: 180,
    // },
    // {
    //   label: "备选4",
    //   field: "spareFour",
    //   width: 180,
    // },
    // {
    //   label: "创建人",
    //   field: "creator",
    //   width: 180,
    // },
    // {
    //   label: "修改人",
    //   field: "reviser",
    //   width: 180,
    // },
    // {
    //   label: "排序",
    //   field: "sort",
    //   width: 120,
    // },
    {
      label: "创建时间",
      field: "create_time",
      width: 200,
    },
    {
      label: "更新时间",
      field: "update_time",
      width: 200,
    },
  ],


  actions: [
    {
      name: "详情",

      buttonClass: 'primary',
      buttonType: 'text',
      click: ({ row, index, handlers }) => {

        //router.push({name: 'CompanyInfoDetail',})
        VDialog.open({
          title: '详情',
          content: { //内容初始形式
            type: 'component', //text:"",预留文本
            name: '/drillExamSubject/detail',
            query: { drillExamSubjectId: row.id },

          },
          callBack: (data: any) => {
            handlers.refresh()
          },
          onClose: () => {
            console.log("对话框已关闭");
          },
        });
      },
      isShow: (row: object) => {
        return true;
      },
      fixed: 'right'
    },
    {
      name: "编辑",
      buttonClass: 'primary',   //按钮颜色控制
      buttonType: 'text',      // 按钮风格   text  link  button
      isShow: (row: object) => {  //根据业务做动态隐藏张氏
        return true
      },
      click: ({ row, index, handlers }) => {        // 点击回调事件方法钩子，  点击触发

        VDialog.open({
          title: '编辑',
          content: { //内容初始形式
            type: 'component', //text:"",预留文本
            name: '/drillExamSubject/edit',
            query: { drillExamSubjectId: row.id },

          },

          callBack: (data: any) => {
            handlers.refresh()
          },
          onClose: () => {
            console.log("对话框已关闭");
          },
        });

      },
      fixed: 'right'
    },

    // {
    //   name: "删除",
    //   buttonClass: 'danger',
    //   buttonType: 'text',
    //   fixed: 'right',
    //   click: ({ row, index, handlers }) => {

    //     $baseConfirm('您确定要删除当前项吗', null, async () => {

    //       const { message } = await DrillExamSubjectApi.del({ drillExamSubjectIds: row.id })
    //       $baseMessage(message, 'success', 'vab-hey-message-success');

    //       handlers.refresh()

    //     })

    //   }
    // },

  ]

})



onActivated(() => {
})



</script>
